//
//  JHSpcialXQTableViewCell.m
//  Liberty Voice
//
//  Created by dlios on 15-5-14.
//  Copyright (c) 2015年 ClearLove. All rights reserved.
//

#import "JHSpcialXQTableViewCell.h"
#import "UIImageView+WebCache.h"

@interface JHSpcialXQTableViewCell ()
@property(nonatomic,retain)UIImageView *ablumBase;

@property(nonatomic,retain)UIImageView *ablumImage;
//@property(nonatomic,retain)UIButton *startButton;
@property(nonatomic,retain)UILabel *ablumTitle;

@property(nonatomic,retain)UIImageView *uSerImage;
@property(nonatomic,retain)UILabel *ablumUser;
@property(nonatomic,retain)UIImageView *playImage;
@property(nonatomic,retain)UILabel *ablumplay;
@property(nonatomic,retain)UIImageView *collectImage;
@property(nonatomic,retain)UILabel *ablumCollect;
@property(nonatomic,retain)UIImageView *commentImage;
@property(nonatomic,retain)UILabel *ablumComment;
@property(nonatomic,retain)UIImageView *durationImage;
@property(nonatomic,retain)UILabel *ablumDuration;
@end

@implementation JHSpcialXQTableViewCell
- (void)dealloc
{
    //    [_hotMusic release];
    [_ablumImage release];
    [_ablumCollect release];
    [_ablumComment release];
    [_ablumDuration release];
    [_ablumplay release];
    [_ablumTitle release];
    [_ablumUser release];
    [_collectImage release];
    [_commentImage release];
    [_playImage release];
    [_uSerImage release];
    [_durationImage release];
    [super dealloc];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        //  底图
        self.ablumBase = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg_share_large"]] autorelease];
        [self.contentView addSubview:_ablumBase];
        //  标题
        self.ablumTitle = [[[UILabel alloc] init]autorelease];
//        _ablumTitle.backgroundColor = [UIColor redColor];
        [_ablumBase addSubview:_ablumTitle];
        //  头像
        self.ablumImage = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1"]] autorelease];
        _ablumImage.layer.cornerRadius = 24.5;
        _ablumImage.layer.masksToBounds = YES;
        [_ablumBase addSubview:_ablumImage];
        //        self.startButton = [UIButton buttonWithType:UIButtonTypeSystem];
        //        [_startButton setImage:[UIImage imageNamed:@"iconfont-play"] forState:UIControlStateNormal];
        //        [_hotMusicImage addSubview:_startButton];
        //  用户名
        self.uSerImage = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iconfont-my"]]autorelease];
        [_ablumBase addSubview:_uSerImage];
        self.ablumUser = [[[UILabel alloc] init] autorelease];
        _ablumUser.font = [UIFont systemFontOfSize:14];
//        _ablumUser.backgroundColor = [UIColor yellowColor];
        [_ablumBase addSubview:_ablumUser];
        //  播放
        self.playImage = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iconfont-play"]] autorelease];
        [_ablumBase addSubview:_playImage];
        self.ablumplay = [[[UILabel alloc] init] autorelease];
        _ablumplay.font = [UIFont systemFontOfSize:10];
//        _ablumplay.backgroundColor = [UIColor blueColor];
        [_ablumBase addSubview:_ablumplay];
        //  收藏
        self.collectImage = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iconfont-xiai"]]autorelease];
        [_ablumBase addSubview:_collectImage];
        self.ablumCollect = [[[UILabel alloc] init] autorelease];
        _ablumCollect.font = [UIFont systemFontOfSize:10];
//        _ablumCollect.backgroundColor = [UIColor brownColor];
        [_ablumBase addSubview:_ablumCollect];
        //  评论
        self.commentImage = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iconfont-mark"]] autorelease];
        [_ablumBase addSubview:_commentImage];
        self.ablumComment = [[[UILabel alloc] init] autorelease];
        _ablumComment.font = [UIFont systemFontOfSize:10];
//        _ablumComment.backgroundColor = [UIColor orangeColor];
        [_ablumBase addSubview:_ablumComment];
        //  时间
        self.durationImage = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iconfont-clock"]] autorelease];
        [_ablumBase addSubview:_durationImage];
        self.ablumDuration = [[[UILabel alloc] init]autorelease];
        _ablumDuration.font = [UIFont systemFontOfSize:10];
//        _ablumComment.backgroundColor = [UIColor grayColor];
        [_ablumBase addSubview:_ablumDuration];
        
    }return self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    _ablumBase.frame = CGRectMake(0, 10, self.contentView.frame.size.width, self.contentView.frame.size.height - 20);
    _ablumImage.frame = CGRectMake(10, 10, 50, 50);
    //    _startButton.frame = CGRectMake(20, 20, _hotMusicImage.frame.size.width - 40, _hotMusicImage.frame.size.height - 40);
    CGFloat f = [[self class] heightWithText:_ablumTitle.text];
    _ablumTitle.frame = CGRectMake(65, 10, 250, f);
    _uSerImage.frame = CGRectMake(65, _ablumTitle.frame.size.height+ 10, 20, 20);
    _ablumUser.frame = CGRectMake(85, _ablumTitle.frame.size.height + 10, 150, 20);
    _playImage.frame = CGRectMake(65, _ablumTitle.frame.size.height + 40, 15, 15);
    _ablumplay.frame = CGRectMake(85, _ablumTitle.frame.size.height + 40, 40, 15);
    _collectImage.frame = CGRectMake(135, _ablumTitle.frame.size.height + 40, 15, 15);
    _ablumCollect.frame = CGRectMake(153, _ablumTitle.frame.size.height + 40, 40, 15);
    _commentImage.frame = CGRectMake(195, _ablumTitle.frame.size.height + 40, 15, 15);
    _ablumComment.frame = CGRectMake(213, _ablumTitle.frame.size.height + 40, 40, 15);
    _durationImage.frame = CGRectMake(255, _ablumTitle.frame.size.height + 40, 15, 15);
    _ablumDuration.frame = CGRectMake(278, _ablumTitle.frame.size.height + 40, 40, 15);
    
}
- (void)setSpecialXQ:(JHSpecialXQ *)specialXQ
{
    if (specialXQ != _specialXQ) {
        [_specialXQ release];
        _specialXQ = [specialXQ retain];
    }
//    NSLog(@"%@", ablum);
    [_ablumImage sd_setImageWithURL:[NSURL URLWithString:specialXQ.coverSmall]];
    _ablumTitle.text = specialXQ.title;
    _ablumUser.text = specialXQ.nickname;
    NSString *num = @"";
    if (specialXQ.playsCounts < 10000) {
        num = [NSString stringWithFormat:@"%ld",specialXQ.playsCounts];
    }else
        if (specialXQ.playsCounts > 10000) {
            //            NSInteger a = (recom.playsCounts / 10000.00);
            num = [NSString stringWithFormat:@"%.1f万",specialXQ.playsCounts / 10000.0];
        }

    _ablumplay.text = num;
    _ablumCollect.text = [specialXQ.favoritesCounts description];
    _ablumComment.text = [specialXQ.commentsCounts description];
    NSString *time = [NSString stringWithFormat:@"%ld:%ld", specialXQ.duration / 60 , specialXQ.duration % 60];
    _ablumDuration.text = time;
}
+ (CGFloat)heightWithText:(NSString *)text
{
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:14]};
    CGSize size = CGSizeMake(360, 1000);
    CGRect rect = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return rect.size.height;
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
